package tcp_net.mail.pop3.commands;

import tcp_net.mail.MailBoxFileManager;
import tcp_net.mail.pop3.commands.debug.DebugInfo;

import java.util.List;
import java.util.ArrayList;

/**
	This class provides a defined command to be executed
	@author J. Okuno
*/
public class PASS extends POP3Command 
{
	/**
		A password
	*/
	private String string;
	
	/**
		Init the class
		@param pass a user account password
		@param man a mailbox file manager
	*/
	public PASS(String pass, MailBoxFileManager man) 
	{ 
		super(man);
		string = pass; 
	}
	
	/**
		This method executes a defined command
		@return a list of reply messages in a string format
	*/
	public List<String> execute() 
	{
		//Search the user's password from username
		String found_pass = manager.getPassword();
		
		//Lock the user's maildrop
		boolean lock = manager.lockMaildrop();
		String rep_msg = "";
		
		//found
		if(found_pass.equals(string) && lock)
		{
			reply = new POP3ReplyMessage(true, "maildrop locked and ready");
			reply_msgs.add(reply.execute().get(0));
		
			return reply_msgs;
		}
		
		//not found
		else if(!found_pass.equals(string))
		{
			rep_msg = "invalid password";
		}
		else if(!lock)
		{
			rep_msg = "unable to lock maildrop";
		}
		
		reply = new POP3ReplyMessage(false, rep_msg);
		return reply.execute();
	}
}